<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\model;

class DistributionConfig extends \app\BaseModel
{
    protected $name = "massage_distribution_config";
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("status desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $this->initData($dis["uniacid"]);
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function defaultConfig()
    {
        $data = [["name" => "getCoachCash", "balance" => 0, "balance_name" => "coach_balance", "top" => 1, "obj_name" => "coach_id"], ["name" => "getUserCash", "balance" => 0, "balance_name" => "user_agent_balance", "top" => 1, "obj_name" => "user_top_id"], ["name" => "getCompanyCash", "balance" => 0, "balance_name" => "company_balance", "top" => 2], ["name" => "getChannelCash", "balance" => 0, "balance_name" => "channel_balance", "top" => 3, "obj_name" => "channel_id"], ["name" => "getCityCash", "balance" => 0, "balance_name" => "city_balance", "top" => 4], ["name" => "getDistrictCash", "balance" => 0, "balance_name" => "district_balance", "top" => 5]];
        return $data;
    }
    public function initData($uniacid)
    {
        $key = "DistributionConfig_key";
        incCache($key, 1, $uniacid, 99);
        $value = getCache($key, $uniacid);
        if($value == 1) {
            $list = $this->defaultConfig();
            foreach ($list as $v) {
                $dis = ["uniacid" => $uniacid, "name" => $v["name"]];
                $find = $this->where($dis)->find();
                if(empty($find)) {
                    $v["uniacid"] = $uniacid;
                    $this->insert($v);
                }
            }
        }
        decCache($key, 1, $uniacid);
        return true;
    }
}

?>